﻿using System;
using System.IO;
using System.Runtime.Serialization;

namespace DevWpfApp
{
    public class MyXml
    {
        public static void SaveXml<T>(string filepath, T obj) where T : new()
        {
            DataContractSerializer s = new DataContractSerializer(typeof(T));
            using (FileStream fs = File.Open(filepath, FileMode.Create))
            {
                s.WriteObject(fs, obj);
            }
        }
        public static T LoadXml<T>(string filepath) where T : new()
        {
            DataContractSerializer s = new DataContractSerializer(typeof(T));

            using (FileStream fs = File.Open(filepath, FileMode.Open))
            {
                T obj = new T();
                Object S2 = s.ReadObject(fs);
                return (T)S2;
            }
        }
    }
}
